/**
 * 
 */
package trungsi.gea.photos.client

import org.json.JSONObject
import org.json.JSONArray

/**
 * @author trungsi
 *
 */
public class JSONConverter{

	static def convert(JSONObject jsonObject) {
        def result = [:]
        jsonObject.keys().each {key ->
            def obj = jsonObject.get(key)
            if (obj instanceof JSONObject || obj instanceof JSONArray) {
                obj = convert(obj)
            }
            result[key] = obj
        }
        
        return result
    }
    
    static def convert(JSONArray jsonArray) {
        def result = []
        (0..<jsonArray.length()).each {
            def obj = jsonArray.get(it)
            if (obj instanceof JSONObject || obj instanceof JSONArray) {
                obj = convert(obj)
            }
            result << obj
        }
        
        return result
    }
	
}
